#include "Gear.h"

int main(int argc, char* argv[])
{
	theLooper loop;
	loop.Run();
	return 0;
}

int theLooper::Run()
{
	video.init();
	mainLoop();
	clean();
	return 0;	
}
void theLooper::mainLoop()
{
	const float FPS = 35.0;

	// Simple FPS limiter. We certainly should tie the movements
	// to the real time passing and never to the frames drawn.
	Uint32 last_time = SDL_GetTicks();
	Uint32 wait;
	int frames_drawn = 0;

	SDL_ShowCursor(SDL_DISABLE);
	SDL_WM_GrabInput(SDL_GRAB_ON);

	do
	{
		try
		{
			video.ProcessEvents();
			video.drawIt();
		}
		catch(...)
		{
		//	report_error(e.What());
		//	if(e.ShouldTerminate()) should_stop = true;
		}
		//cout << "xpos: " << player.xpos << "\tzpos: " << player.zpos << endl;
		//frames_drawn++;

		wait = SDL_GetTicks() - last_time;
		if(wait < 1000.0 / FPS) SDL_Delay( (Uint32)(1000.0 / FPS - wait) );
		last_time = SDL_GetTicks();
	} while(!video.should_stop);

	SDL_WM_GrabInput(SDL_GRAB_OFF);
	SDL_ShowCursor(SDL_ENABLE);
}

int theLooper::clean()
{
	SDL_Quit();
	return 0;
}